package com.qi.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qi.common.RoleKey;
import com.qi.pojo.dto.AddActProBody;
import com.qi.pojo.entity.Activity;
import com.qi.pojo.entity.ActivityProcess;
import com.qi.pojo.vo.AjaxResult;
import com.qi.services.IActivityProcessService;
import com.qi.services.IActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/actPro")
@Tag(name = "活动管理")
public class ActivityController {

    @Resource
    private IActivityProcessService activityProcessService;

    @Resource
    private IActivityService activityService;

    @SaCheckRole(RoleKey.社团管理员)
    @Operation(summary = "新增活动")
    @PostMapping("/addActivity")
    public AjaxResult addActivity(@RequestBody AddActProBody addActProBody) {
        activityProcessService.addActivity(addActProBody);
        return AjaxResult.ok("提交成功，等待超级管理员审批");
    }

    @SaCheckRole(RoleKey.超级管理员)
    @Operation(summary = "查询待审核活动")
    @GetMapping("/getPendingList/{current}/{size}")
    public AjaxResult getPendingList(@PathVariable("current") Long current,
                                     @PathVariable("size") Long size) {

        IPage<ActivityProcess> pendingList = activityProcessService.getPendingList(current, size);
        return AjaxResult.success(pendingList);
    }

    @SaCheckRole(RoleKey.超级管理员)
    @Operation(summary = "批准举办活动")
    @GetMapping("/approvalHold/{actProId}")
    public AjaxResult approvalHold(@PathVariable("actProId") Long actProId) {
        activityProcessService.approvalHold(actProId);
        return AjaxResult.ok("批准成功");
    }

    @SaCheckRole(RoleKey.超级管理员)
    @Operation(summary = "拒绝举办活动")
    @GetMapping("/rejectHold/{actProId}")
    public AjaxResult rejectHold(@PathVariable("actProId") Long actProId) {
        activityProcessService.rejectHold(actProId);
        return AjaxResult.ok("拒绝成功");
    }

    @SaCheckLogin
    @Operation(summary = "查询本社团活动列表")
    @GetMapping("/nativeList/{current}/{size}")
    public AjaxResult nativeList(@PathVariable("current") Long current,
                           @PathVariable("size") Long size) {
        IPage<Activity> activityList = activityService.nativeList(current, size);
        return AjaxResult.success(activityList);
    }

    @SaCheckRole(RoleKey.超级管理员)
    @Operation(summary = "查询所有活动")
    @GetMapping("/list/{current}/{size}")
    public AjaxResult list(@PathVariable("current") Long current,
                                 @PathVariable("size") Long size) {
        IPage<Activity> activityList = activityService.getList(current, size);
        return AjaxResult.success(activityList);
    }
}
